--[[
重置桶状态脚本 - 使用JSON格式
KEYS[1]: bucket key
ARGV[1]: capacity
ARGV[2]: refillRate
ARGV[3]: currentTime  
ARGV[4]: expireSeconds

返回: 1(成功) 或 0(失败)
--]]

local key = KEYS[1]
local capacity = tonumber(ARGV[1])
local refillRate = tonumber(ARGV[2])
local now = tonumber(ARGV[3])
local expireSeconds = tonumber(ARGV[4])

-- 创建重置后的桶状态
local bucketState = {
    capacity = capacity,
    tokens = capacity,  -- 重置为满容量
    refillRate = refillRate,
    lastRefillTime = now,
    createdAt = now,
    resetAt = now
}

-- 保存桶状态 (JSON格式)
redis.call('SET', key, cjson.encode(bucketState))
redis.call('EXPIRE', key, expireSeconds)

return 1 